#!/usr/bin/python3
from openpyxl import load_workbook
import gc


class ProjectConfigReader:
    """读取工程配置"""

    def __init__(self) -> None:
        super().__init__()

    def read_config(self, path):
        """
        读取配置
        """
        workbook = load_workbook(path)
        config_sheet = workbook["工程配置"]
        properties = {}
        properties["通用开始行"] = config_sheet["D2"].value
        properties["列字段开始行"] = config_sheet["E2"].value
        properties["角色初始化列"] = config_sheet["F2"].value.split(",")
        properties["角色初始化开始列"] = int(properties["角色初始化列"][0])
        properties["角色初始化结束列"] = int(properties["角色初始化列"][1])
        properties["权限初始化列"] = config_sheet["G2"].value.split(",")
        properties["权限初始化开始列"] = int(properties["权限初始化列"][0])
        properties["权限初始化结束列"] = int(properties["权限初始化列"][1])
        properties["背景色"] = config_sheet["H2"].fill.copy()
        properties["前景色"] = config_sheet["H2"].font.copy()
        properties["文字居中"] = config_sheet["H3"].alignment.copy()
        properties["两侧边框"] = config_sheet["H4"].border.copy()
        del workbook
        gc.collect()
        return properties
